import java.util.Stack;

// eg2 -- 232. 用栈实现队列
class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>(); //将所有的元素都入s1栈
        s2 = new Stack<>(); //s2用于出栈
    }

    //将元素 x 推到队列的末尾
    public void push(int x) {
        s1.push(x);
    }

    // 从队列的开头移除并返回元素
    public int pop() {
        if(empty()){
            return -1;
        }
        if(s2.empty()){
            while (!s1.empty()){
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    //返回队列开头的元素
    public int peek() {
        if(empty()){
            return -1;
        }
        if(s2.empty()){
            while (!s1.empty()){
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    //如果队列为空，返回 true ；否则，返回 false
    public boolean empty() {
        return s1.empty() && s2.empty();
    }
}